package com.guyu.app.admin.controller;

import com.guyu.app.common.biz.handler.FileUploadHandler;
import com.guyu.common.core.entity.BizResult;
import com.guyu.plugin.oss.entity.UploadResult;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.MediaType;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;


@Tag(name = "文件上传接口")
@Slf4j
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/a/file")
public class FileController extends BaseController {

    private final FileUploadHandler fileUploadHandler;

    /**
     * 通用文件上传
     */
    @Operation(summary = "文件上传", description = """
            1，目前只支持单文件上传
            2，上传成功之后，如果作为参数要提交给其他接口请使用 filename 参数
            """)
    @PostMapping(value = "/upload", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
    public BizResult<UploadResult> upload(@RequestPart("file") MultipartFile file) {
        UploadResult result = fileUploadHandler.upload(file);
        return BizResult.create(result);
    }

}
